package com.app.util.array;

import java.util.Date;

import com.app.util.date.DateUtil;


public class ArrayItemUtil {

	public static <T> T getItem(T[] arr, int index) {
		if (null == arr || index >= arr.length) {
			return null;
		}
		return arr[index]; 
	}

	public static String getStringItem(Object[] arr, int index) {
		if (null == arr || index >= arr.length) {
			return null;
		}
		return arr[index].toString();
	}

	public static Integer getIntegerItem(Object[] arr, int index) {
		if (null == getStringItem(arr, index)) {
			return null;
		}
		return Integer.parseInt(getStringItem(arr, index));
	}

	public static Long getLongItem(Object[] arr, int index) {
		if (null == getStringItem(arr, index)) {
			return null;
		}
		return Long.parseLong(getStringItem(arr, index));
	}

	public static Date getDateItem(Object[] arr, int index, String format) {
		if (null == getStringItem(arr, index)) {
			return null;
		}
		return DateUtil.parse(getStringItem(arr, index), format);
	}

	public static <T> T getFirstNotNull(T[] arr) {
		if (null == arr) {
			return null;
		}
		for (T o : arr) {
			if (null != o) {
				return o;
			}
		}
		return null;
	}
}
